<?php
require_once dirname(__FILE__) . '/../../../incls/php/dbutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/config.php';
$myPdo = DbUtils::createPdoInst();
$page_id = MiscUtils::getParam('i', 0);

$SIZE = 50;
$page = MiscUtils::getParam('p', 1);
$order = MiscUtils::getParam('o', 't.title');
$queue = MiscUtils::getParam('q', 'ASC');
$items = DbUtils::get($myPdo,  TABLE_NAME_PREFIX_PLUGIN . 'ecom_mthd_payment', NULL, $order, $queue, $page, $SIZE, NULL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style>
* {
  font-family: Trebuchet MS;
  font-size: 12px;
  padding: 0;
  margin: 0;
}
table.list {
  border-left: 1px solid #666;
  border-top: 1px solid #666;
  font-size: 12px;
  width: 500px;
}
table.list th.sort {
  text-align: left;
  height: 28px;
  background-color: #222;
  padding: 0 5px; 
  border-right: 1px solid #666;
  border-bottom: 1px solid #666;
  font-weight: bold;
  vertical-align: middle;
  cursor: pointer;
  color: #fff;
}
table.list tr.rowodd td {
  padding: 0 5px;
  height: 25px;
  background-color: #eee;
  border-right: 1px solid #666;
  border-bottom: 1px solid #666;
  word-wrap: break-word;
  vertical-align: middle;
}
table.list tr.roweven td {
  padding: 0 5px;
  height: 25px;
  background-color: #fff;
  border-right: 1px solid #666;
  border-bottom: 1px solid #666;
  word-wrap: break-word;
  vertical-align: middle;
}
table.list tr.rowodd:hover td {
  background-color: #f4f3b2;
}
table.list tr.roweven:hover td {
  background-color: #f4f3b2;
}
table.list tr.none td {
  padding: 0 5px;
  height: 25px;
  background-color: #fff;
  border-right: 1px solid #666;
  border-bottom: 1px solid #666;
  word-wrap: break-word;
}
.imgbtn {
  background-image: url(assets/imgs/add.png);
  background-repeat: no-repeat;
  background-position: 5px 2px;
  padding: 5px 5px 5px 30px;
  border: 1px solid #666;
  background-color: #fff;
  cursor: pointer;
  border-radius: 3px;
}
.imgbtn:hover {
  background-color: #eee;
}
.imgico {
  cursor: pointer;
}
</style>
</head>
<body>
<button class="imgbtn" onclick="parent.location.href='http://<?php echo URL . "admin.php?i=$page_id&script=index_payment"; ?>';">New Payment</button>
<div>
  <table class="list" style="margin-top: 5px;" cellPadding="0" cellSpacing="0">
    <tr>
      <th class="sort" onclick="set_order('title')">Name</th>
      <th class="sort" width="50px">Available</th>
      <th class="sort" width="40px"></th>
    </tr>
    <?php foreach ($items->d as $idx => &$item) { ?>
    <tr class="<?php echo (($idx % 2 == 0) ? 'roweven' : 'rowodd'); ?>">
      <td><?php echo $item->title; ?></td>
      <td><input type="checkbox" onchange="setAvailable(this, '<?php echo $item->id; ?>')" <?php echo (($item->status == 1) ?  "checked='checked'" : "");?>></input></td>
      <td>
        <img src="assets/imgs/edit.png" class="imgico" onclick="parent.location.href='http://<?php echo URL . "admin.php?i=$page_id&script=index_payment&id=$item->id"; ?>';"></img>
        <img src="assets/imgs/delete24.png" class="imgico" onclick="del_payment('<?php echo $item->id; ?>');"></img>
      </td>
    </tr>
    <?php } ?>
    <?php if (count($items->d) == 0) { ?>
    <tr class="none" ><td colspan=3>No Results</td></tr>
    <?php } ?>
  </table>
</div>
<script type="text/javascript" src="../../../libs/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../../../incls/js/myutils.js"></script>
<script type="text/javascript">
  function set_order(col) {
    parent.location.href='http://<?php echo URL. "admin.php?i=$page_id&q=" . (($items->q == 'ASC') ? 'DESC' : 'ASC'); ?>&o=' +  col;
  }

  function del_payment(id) {
    r = window.confirm('Are You Sure?');
    if (!r) {
      return;
    }
    $.ajax({
      type: "POST",
      url: "<?php echo basename(__FILE__, '.php'); ?>.server.php",
      data: "action=del_payment&q=" + encodeURIComponent(id),
      success: function(msg){
        location.reload();
      }
    });
  }

  function setAvailable(elm, id) {
    var available = 0;
    if (elm.checked) {
      available = 1;
    } else {
      available = 0;
    }
    
    $.ajax({
      type: "POST",
      url: "<?php echo basename(__FILE__, '.php'); ?>.server.php",
      data: "action=set_available&q=" + encodeURIComponent(JSON.stringify({id: id, available: available})),
      success: function(msg){
        location.reload();
      }
    });
  }
</script>
</body>
</html>